package ru.gerunn.silent.common;

import ru.gerunn.silent.exception.SilentReadMessageException;
import ru.gerunn.silent.exception.SilentWriteMessageException;
import ru.gerunn.silent.message.Message;

public class RW extends Thread {

	private Reader reader;
	private Writer writer;

	public RW(Reader reader, Writer writer) {
		this.reader = reader;
		this.writer = writer;
	}

	public void run() {
		Message message;
		try {
			while ((message = this.reader.read()) != null) {
				writer.write(message);
			}
		} catch (SilentReadMessageException e) {
			e.printStackTrace();
		} catch (SilentWriteMessageException e) {
			e.printStackTrace();
		}
	}

}
